package utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;

public class Test_DBCP {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement st = null;
        try {
            conn = JdbcUtils_DBCP.getConnection();
            //?是占位符 代替参数
            String sql = "INSERT INTO `Users`(`UId`,`Password`,`Email`,`RegistrationTime`) VALUES(?,?,?,?)";

            st = conn.prepareStatement(sql);//预编译sql 先写sql 但是不执行
            //手动给参数赋值
            st.setString(1, "das");
            st.setString(2, "abc");
            st.setString(3, "123456");

            //sql.Date
            //java.util.Date  //获得时间戳 然后传给sql.Date
            st.setDate(4, new java.sql.Date(new Date().getTime()));

            //以上填充完毕 然后执行
            int i = st.executeUpdate();
            if (i > 0) {
                System.out.println("插入成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JdbcUtils_DBCP.release(conn, st, null);
        }

    }
}



